package it.slothy.noveleditor.gui.component;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JLabel;

public class ActionComponent extends JComponent{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//Variabili da visualizzare
	private String name;
	private String description;
	
	//Component del disegno
	private static Color[] unfocusColor = {new Color(237,248,247), new Color(210,227,226)};
	private static Color[] focusColor = {new Color(210,227,226), new Color(237,248,247)};
	
	private Color[] usedColor = unfocusColor;
	
	private JLabel lblTitle;
	private JLabel lblSubTitle;
	
	public ActionComponent(String n, String d){
		
		this.name = n;
		this.description = d;
		
		this.lblTitle = new JLabel(this.name);
		this.lblTitle.setBounds(100, 20,100,100);
		this.add(lblTitle);
		this.lblSubTitle = new JLabel(this.description);
		this.lblSubTitle.setBounds(100, 50,100,100);
		this.add(lblSubTitle);
		
		this.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				usedColor = focusColor;
				
				repaint();
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				usedColor = unfocusColor;
				
				repaint();
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				
			}
			
		});
	}
	
	@Override
	public void paintComponent(Graphics g){
		this.setSize(this.getParent().getWidth(), 100);
			Graphics2D g2d = (Graphics2D) g;
        Color color1 = usedColor[0];
        Color color2 = usedColor[1];
        int w = getWidth();
        int h = getHeight();
        GradientPaint gp = new GradientPaint(0, 0, color1, 0, h, color2);
        g2d.setPaint(gp);
        g2d.fillRoundRect(5, 5, w - 10, h - 10, 40, 40);
	}

}
